/**
 * Created by huhai on 17/9/27.
 */
/**
 * Created by huhai on 17/9/25.
 */
import {handleActions} from 'redux-actions'
import * as TYPES from "../constants/actions"

export default   handleActions({
  [TYPES.GET_TEMPLATES]: (state, result) => {
    if(!result.error && result.payload && result.payload.data.success){
      let end = Object.assign({},state,{templatesInfo: result.payload.data.data})
      return end
    }
    return state

  },
 [TYPES.GET_MODULE_DETAIL]: (state, result) => {
    if(!result.error && result.payload && result.payload.data.success){
      let end = Object.assign({},state,{moduleDetail: result.payload.data.data})
      return end
    }
    return  Object.assign({},state,{textData: '没有获取到此模块的文字信息,请点击重试'})
  },
  [TYPES.GET_MODULE_DATA]: (state, result) => {
    if(!result.error && result.payload && result.payload.data.success){
      let end = Object.assign({},state,{moduleData: result.payload.data.data, moduleOldData: result.payload.data.data})
      return end
    }
    return  Object.assign({},state,{textData: '没有获取到此模块的数据信息,请点击重试'})
  },
  [TYPES.SAVE_TEXTAREA]: (state, result) => {
    if(!result.error){
      let end = Object.assign({},state,{moduleDetail: {...state.moduleDetail,txtData: result.payload ? result.payload : ''}})
      return end
    }
    return state
  },
  [TYPES.SAVE_DATAAREA]: (state, result) => {
    if(result.globalStyle === 1){
      let end = Object.assign({}, state,{moduleData: result.payload})
      return end
    }else{
      if(!result.error){
        let end = Object.assign({},state,{moduleData: {...state.moduleData,chartData: result.payload ? result.payload : ''}, moduleOldData: {...state.moduleOldData}})
        return end
      }
    }

    return state
  },
  [TYPES.CHECK_CHART]: (state, result) => {
    if(!result.error && result.payload && result.payload.data.success){
      let end = Object.assign({},state,{checkChart: result.payload.data.message})
      return end
    }
    return  Object.assign({},state,{checkChart: '没有获取到数据'})
  },
}, {templatesInfo: []});
